package cn.zdq.picture_lib.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import cn.zdq.picture_lib.R;
import cn.zdq.picture_lib.model.LocalMedia;
import cn.zdq.picture_lib.myselfview.photoview.PhotoView;

/**
 * @Description:
 * @Author: zhoudequn
 * @CreateDate: 2021/10/13 14:29
 */
public class ViewPager2Adapter extends RecyclerView.Adapter<ViewPager2Adapter.ViewPagerViewHolder> {

    private List<LocalMedia> mDatas;

    private Context mContext;

    public ViewPager2Adapter(List<LocalMedia> datas) {
        mDatas = datas;
    }

    @NonNull
    @NotNull
    @Override
    public ViewPagerViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_picture_preview, parent, false);
        mContext = parent.getContext();
        return new ViewPagerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull ViewPagerViewHolder holder, int position) {
        Glide.with(mContext)
                .load(mDatas.get(position).getPath())
                .into(holder.photoView);
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    class ViewPagerViewHolder extends RecyclerView.ViewHolder {
        PhotoView photoView;

        public ViewPagerViewHolder(@NonNull View itemView) {
            super(itemView);
            photoView = itemView.findViewById(R.id.preview_image);
        }
    }
}
